package cloud.kiko.psn.card.rest;

import cloud.kiko.psn.card.service.CardService;
import cloud.kiko.psn.pojo.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 2024/7/15 3:14
 */
@RestController
@RequestMapping("card")
@Slf4j
public class CardRest {
    private final CardService cardService;

    public CardRest(CardService cardService) {
        this.cardService = cardService;
    }

    /**
     * 支付服务
     *
     * @param userId   用户id
     * @param opAmount 支付金额
     */
    @PutMapping("pay/{userId}/{opAmount}")
    R<?> pay(@PathVariable("userId") Long userId, @PathVariable("opAmount") Double opAmount) {
        log.info("用户：{}，支付金额：{}", userId, opAmount);
        if (cardService.pay(userId, opAmount)) {
            return R.ok("支付金额："+opAmount,"支付成功");
        }
        return R.notOk("支付失败");

    }

    /**
     * 充值服务
     *
     * @param userId   用户id
     * @param opAmount 充值金额
     */
    @PutMapping("deposit/{userId}/{opAmount}")
    R<?> deposit(@PathVariable("userId") Long userId, @PathVariable("opAmount") Double opAmount) {
        log.info("用户：{}，充值金额：{}", userId, opAmount);
        if (cardService.deposit(userId, opAmount)) {
            return R.ok("充值金额："+opAmount,"充值成功");
        }
        return R.notOk("充值失败");
    }
}
